package com.demo.controller;


import com.demo.service.index.IndexService;
import com.demo.service.index.entity.IndexEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/")
public class IndexController {
    @Autowired
    private IndexService indexService;

    @RequestMapping("index")
    public String  index(){

        IndexEntity ie = new IndexEntity();
        //ie.setId("1111111");
        ie.setName("index");
        indexService.saveIndex(ie);
        StringBuffer bf = new StringBuffer();
        System.out.println("--------selectAll method test-------");
        //查询全部用户，参数是一个Wrapper，条件构造器，先不使用为null
        List<IndexEntity> indexlist  = indexService.getindex();
        indexlist.stream().forEach((item)->{
            bf.append("id = "+item.id +" , "+"name = "+item.getName() +"\r\n");
        });
        System.out.println(bf.toString());
        return bf.toString();
    }

    @RequestMapping("index2")
    @Transactional
    public String  index2(){

        IndexEntity ie = new IndexEntity();
        //ie.setId("1111111");
        ie.setName("index");
        indexService.saveIndex(ie);
        StringBuffer bf = new StringBuffer();
        System.out.println("--------selectAll method test-------");
        //查询全部用户，参数是一个Wrapper，条件构造器，先不使用为null
        List<IndexEntity> indexlist  = indexService.getindex();
        indexlist.stream().forEach((item)->{
            bf.append("id = "+item.id +" , "+"name = "+item.getName() +"\r\n");
        });
        System.out.println(bf.toString());
        return bf.toString();
    }

}
